package com.hzcx.app.simplechat.model;

import android.content.Context;

import com.hzcx.app.simplechat.api.APIRequest;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.api.RxHelper;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.ui.login.bean.LoginInfoBean;
import com.hzcx.app.simplechat.ui.login.bean.PhoneCityBean;
import com.hzcx.app.simplechat.ui.login.bean.UserRegisterBean;
import com.hzcx.app.simplechat.util.app.AppHelper;
import com.hzcx.app.simplechat.util.system.IMEI;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import java.util.List;

public class LoginModel {

    /**
     * 密码登录
     *
     * @param context
     * @param phone
     * @param pwd
     * @param observer
     */
    public static void loginByPwd(Context context, String phone, String pwd, String area_code, BaseObserver<LoginInfoBean> observer) {
        APIRequest
                .getRequestInterface()
                .loginByPwd(phone, pwd, AppHelper.getDeviceBrand(), area_code, IMEI.getDeviceIMEI())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取号码前缀地区城市
     *
     * @param context
     * @param observer
     */
    public static void getPhoneCity(Context context, BaseObserver<List<PhoneCityBean>> observer) {
        APIRequest
                .getRequestInterface()
                .getPhoneCity()
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 验证码登录
     *
     * @param context
     * @param mobile
     * @param captcha
     * @param observer
     */
    public static void loginByCode(Context context, String mobile, String captcha, String area_code, BaseObserver<LoginInfoBean> observer) {
        APIRequest
                .getRequestInterface()
                .loginByCode(mobile, captcha, AppHelper.getDeviceBrand(), area_code, IMEI.getDeviceIMEI())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 忘记密码-重置密码
     *
     * @param context
     * @param newpassword
     * @param captcha
     * @param mobile
     * @param observer
     */
    public static void forgetPwd(Context context, String newpassword, String captcha, String mobile, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .forgetPwd(newpassword, captcha, mobile)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 阿里云一键登录
     *
     * @param context
     * @param accessToken
     * @param logindevice
     * @param observer
     */
    public static void loginByAli(Context context, String accessToken, String logindevice, BaseObserver<LoginInfoBean> observer) {
        APIRequest
                .getRequestInterface()
                .loginByAli(accessToken, logindevice, IMEI.getDeviceIMEI())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 微信登录
     *
     * @param context
     * @param code
     * @param logindevice
     * @param observer
     */
    public static void loginByWx(Context context, String code, String logindevice, BaseObserver<LoginInfoBean> observer) {
        APIRequest
                .getRequestInterface()
                .loginByWx(code, logindevice, IMEI.getDeviceIMEI())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 通过阿里token绑定手机号
     *
     * @param context
     * @param token
     * @param accessToken
     * @param observer
     */
    public static void bindPhoneByAli(Context context, String token, String accessToken, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .bindPhoneByAli(token, accessToken)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     *  获取用户是否注册
     * @param context
     * @param mobile
     * @param area_code
     * @param uniquely
     * @param observer
     */
    public static void getUserIsRegister(Context context, String mobile, String area_code, String uniquely, BaseObserver<UserRegisterBean> observer) {
        APIRequest
                .getRequestInterface()
                .getUserIsRegister(mobile, area_code, uniquely)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }
}
